package Frame;

import Function.FCActionLibrary;
import Function.FCEventLibrary;
import Function.FCItemLibrary;
import Function.FCTankLibrary;
import VWorldGameStudio.FCTank;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;

public class FCTankAndActionTable extends JDialog {
	private int w, h, firstnum = 0;

	public <T> FCTankAndActionTable(FCTankLibrary event, FCItemLibrary actionl) {
		setBounds(0, 0, 1200, 800);
		w = getWidth();
		h = getHeight();
		setLayout(null);
		setLocationRelativeTo(null);
		setResizable(false);
		setModal(true);
		setTitle("查看坦克");

//		JTabbedPane q=new JTabbedPane();
//		q.setBounds(0, 0, getWidth(), getHeight());
//		this.add(q);

//		new String[] {"ID","描述"}, new String[][] {{"1","12314231"},{"2","1asfwqafagf2314231"}}
//		JTable a=new JTable(ee,ss);
//		q.add(a);
		// 心累，自己做一个表格

		JPanel t = new JPanel() {
			private Color c1 = new Color(220, 220, 220);
			private Font f1 = new Font("黑体", 0, 15);
			private Font f2 = new Font("黑体", 0, 13);

			@Override
			protected void paintComponent(Graphics g) {
//				System.out.println("刷新"+firstnum);
				// 表头
				g.setColor(c1);
				g.fillRect(0, 0, w, 16);
				g.setColor(new Color(240, 240, 240));
				g.fillRect(0, 17, w, h - 17);
				g.setColor(Color.black);
				g.setFont(f1);
				g.drawString("ID", 10, 14);
				g.drawString("描述", 210, 14);
				g.drawLine(200, 0, 200, 16);
				g.drawLine(0, 16, w, 16);
				g.setFont(f2);
				int nn = event.getTankAllNum();
				for (int i = 0; i < nn; i++) {
					FCTank fcTank = event.getTankOfNum(i);
					g.drawString(fcTank.toString(), 5,30 + 80 * i);
					g.drawString(fcTank.toString2(), 5,50 + 80 * i);
					g.drawLine(0, 80 + 80 * i, w, 80 + 80 * i);
				}
			}
		};
		t.setBounds(0, 0, getWidth(), getHeight());
		this.add(t);

		addMouseWheelListener(new MouseWheelListener() {
			@Override
			public void mouseWheelMoved(MouseWheelEvent e) {
				if (e.getWheelRotation() > 0) {
					if (firstnum < event.getTankAllNum())
						firstnum++;
				} else if (firstnum > 0)
					firstnum--;
				t.updateUI();
			}
		});

		setVisible(true);
	}
}
